Skip to content

refactor(template): simplify tests with table-driven approach and golden files#417

Merged
dirien merged 1 commit intomainfrom
dirien/simplify-template-tests
Dec 24, 2025
Merged

refactor(template): simplify tests with table-driven approach and golden files#417
dirien merged 1 commit intomainfrom
dirien/simplify-template-tests

Conversation

@dirien
Copy link
Copy Markdown
Owner

@dirien dirien commented Dec 24, 2025

Summary

  • Refactor template tests from ~4,400 lines to ~280 lines using table-driven approach
  • Extract expected outputs to 31 golden files in testdata/ directory
  • Add helper functions (makeBaseResource, makeJavaResource, makeBedrockResource) for creating test fixtures
  • Support -update flag for easy golden file maintenance when templates change

Changes

  • Replace 26+ separate test functions with 3 clean table-driven tests:
    • TestBashTemplates (15 test cases)
    • TestCloudInitTemplates (11 test cases)
    • TestConfigTemplates (5 test cases)
  • Move expected outputs to template/testdata/*.golden files
  • Add golden file helpers: loadGolden(), updateGolden(), assertGolden()

Test plan

  • All template tests pass (go test ./template/...)
  • Full test suite passes (go test ./...)
  • Code passes go vet and go fmt

🤖 Generated with Claude Code

…den files

Refactor the template test file to reduce code duplication and improve
maintainability:

- Replace 26+ separate test functions with 3 table-driven tests
- Extract expected outputs to golden files in testdata/ directory
- Add helper functions for creating test fixtures
- Support -update flag for easy golden file maintenance

This reduces the test file from ~4,400 lines to ~280 lines while
maintaining the same test coverage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Engin Diri <engin.diri@ediri.de>
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
8.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@dirien dirien merged commit 8202056 into main Dec 24, 2025
3 of 4 checks passed
@dirien dirien deleted the dirien/simplify-template-tests branch December 24, 2025 10:21
@github-actions
Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant